package com.relsell.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;

import com.relsell.pointofsales.R;

public class Reports extends Fragment {

	public Reports() {

	}

	ExpandableListAdapter listAdapter;
	ExpandableListView expListView;
	List<String> listDataHeader;
	HashMap<String, List<String>> listDataChild;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.list_exp_main, container, false);

		// get the listview
		expListView = (ExpandableListView) v.findViewById(R.id.lvExp);

		// preparing list data
		prepareListData();

		listAdapter = new ExpandableListAdapter(this.getActivity(),
				listDataHeader, listDataChild);

		// setting list adapter
		expListView.setAdapter(listAdapter);

		// Listview Group click listener
		expListView.setOnGroupClickListener(new OnGroupClickListener() {

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				// Toast.makeText(getApplicationContext(),
				// "Group Clicked " + listDataHeader.get(groupPosition),
				// Toast.LENGTH_SHORT).show();
				return false;
			}
		});

		// Listview Group expanded listener
		expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

			@Override
			public void onGroupExpand(int groupPosition) {
				Toast.makeText(getActivity(),
						listDataHeader.get(groupPosition) + " Expanded",
						Toast.LENGTH_SHORT).show();
			}
		});

		// Listview Group collasped listener
		expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

			@Override
			public void onGroupCollapse(int groupPosition) {
				Toast.makeText(getActivity(),
						listDataHeader.get(groupPosition) + " Collapsed",
						Toast.LENGTH_SHORT).show();

			}
		});

		// Listview on child click listener
		expListView.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				Toast.makeText(
						getActivity(),
						listDataHeader.get(groupPosition)
								+ " : "
								+ listDataChild.get(
										listDataHeader.get(groupPosition)).get(
										childPosition), Toast.LENGTH_SHORT)
						.show();
				return false;
			}
		});

		return v;
	}

	private void prepareListData() {

		listDataHeader = new ArrayList<String>();
		listDataChild = new HashMap<String, List<String>>();

		// Adding child data
		listDataHeader.add("Janurary");
		listDataHeader.add("Feburary");
		listDataHeader.add("March");
		listDataHeader.add("April");
		listDataHeader.add("May");
		listDataHeader.add("June");
		listDataHeader.add("July");
		listDataHeader.add("August");
		listDataHeader.add("September");
		listDataHeader.add("October");
		listDataHeader.add("November");
		listDataHeader.add("December");

		// Adding child data
		List<String> jan = new ArrayList<String>();
		jan.add("Week 1");
		jan.add("Week 2");
		jan.add("Week 3");
		jan.add("Week 4");

		List<String> feb = new ArrayList<String>();
		feb.add("Week 1");
		feb.add("Week 2");
		feb.add("Week 3");
		feb.add("Week 4");

		List<String> mar = new ArrayList<String>();
		mar.add("Week 1");
		mar.add("Week 2");
		mar.add("Week 3");
		mar.add("Week 4");
		
		List<String> apr = new ArrayList<String>();
		apr.add("Week 1");
		apr.add("Week 2");
		apr.add("Week 3");
		apr.add("Week 4");
		
		List<String> may = new ArrayList<String>();
		may.add("Week 1");
		may.add("Week 2");
		may.add("Week 3");
		may.add("Week 4");
	
		List<String> jun = new ArrayList<String>();
		jun.add("Week 1");
		jun.add("Week 2");
		jun.add("Week 3");
		jun.add("Week 4");
		
		List<String> jul = new ArrayList<String>();
		jul.add("Week 1");
		jul.add("Week 2");
		jul.add("Week 3");
		jul.add("Week 4");
	
		List<String> aug = new ArrayList<String>();
		aug.add("Week 1");
		aug.add("Week 2");
		aug.add("Week 3");
		aug.add("Week 4");
		
		
		List<String> sep = new ArrayList<String>();
		sep.add("Week 1");
		sep.add("Week 2");
		sep.add("Week 3");
		sep.add("Week 4");
		
		List<String> oct = new ArrayList<String>();
		oct.add("Week 1");
		oct.add("Week 2");
		oct.add("Week 3");
		oct.add("Week 4");
		List<String> nov = new ArrayList<String>();
		nov.add("Week 1");
		nov.add("Week ");
		nov.add("Week 3");
		nov.add("Week 4");
		
		List<String> dec = new ArrayList<String>();
		dec.add("1");
		dec.add("2");
		dec.add("3");
		dec.add("4");
		dec.add("5");

		listDataChild.put(listDataHeader.get(0), jan); // Header, Child data
		listDataChild.put(listDataHeader.get(1), feb);
		listDataChild.put(listDataHeader.get(2), mar);
		listDataChild.put(listDataHeader.get(3), apr); // Header, Child data
		listDataChild.put(listDataHeader.get(4), may);
		listDataChild.put(listDataHeader.get(5), jun);
		listDataChild.put(listDataHeader.get(6), jul); // Header, Child data
		listDataChild.put(listDataHeader.get(7), aug);
		listDataChild.put(listDataHeader.get(8), sep);
		listDataChild.put(listDataHeader.get(9), oct); // Header, Child data
		listDataChild.put(listDataHeader.get(10), nov);
		listDataChild.put(listDataHeader.get(11), dec);

	}

}
